Ext.onReady(function(){ 

Ext.QuickTips.init();

var fm = Ext.form;

//Gridpanel
var cm=new Ext.grid.ColumnModel([
{header:'流水号',dataIndex:'serialNo',hidden:true,
editor: new fm.TextField({allowBlank: false,editable:false,readOnly:true})
} ,
{header:'评级结果名称',
	dataIndex:'pdlevel',
	width:100,
	editor: new fm.TextField({
                allowBlank: false
            })
    },
{header:'PD值',
		dataIndex:'pdvalue',
		width:100,
		editor: new fm.NumberField({
                allowBlank: false,
                allowNagetive:false
            })	
}
]);  

var ds = new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'model/listMainScaleInfo.do',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'serialNo'},
{name:'pdlevel'}, 
{name:'pdvalue'}
]) 
}); 
ds.load(); 



var grid=new Ext.grid.EditorGridPanel({ 
id:'myCustomers',
renderTo:'panel',
stripeRows:true,//斑马线效果
title:'<div align="center">主标尺</div>', 
width:'400',
height:500, 
cm:cm,
store: ds, 
clicksToEdit: 2,
 tbar: [{
            text: '添加',
            handler : function(){
              
                var n = grid.getStore().getCount();// 获得总行数 
                var MainscaleInfo = grid.getStore().recordType;
                var ml = new MainscaleInfo({
                	serialNo:'',
                	pdlevel:'',
                	pdvalue:''
                });
                grid.stopEditing();
                ds.insert(n, ml);
                grid.startEditing(0, 0);
            }
        },'-',
        {text:'提交',  handler:submitM},'-',
        {text:'取消',  handler:function(){grid.store.reload();ds.rejectChanges();}},
        ],
loadMask: { msg: "加载中..." }, 
viewConfig: {   forceFit:true   }  
                      
});

function submitM(){
	var mr=ds.getModifiedRecords();//获取所有更新过的记录  
     var recordCount=ds.getCount();//获取数据集中记录的数量  
     if(mr.length==0){  // 确认修改记录数量  
       alert("没有修改数据！");  
       return false;  
     }  
       
     var recordModStr="[";//这里以josn方式保存  
     for(var i=0;i<mr.length;i++){ 
    // recordModStr+=Ext.util.JSON.encode(mr[i].data);
    
      recordModStr+="{serialNo:"+"\""+mr[i].data["serialNo"]+"\""+",pdlevel:"+"\""+mr[i].data["pdlevel"]+"\""+",pdvalue:"+mr[i].data["pdvalue"]+"}";  
      if(i<mr.length-1)  
      	recordModStr+=",";  
    } 
     recordModStr+="]";
    
     Ext.Ajax.request({
		url:'model/addMainscaleInfo.do',
		params : { newRecord: recordModStr},
		method:'POST',
		success:function(){
			Ext.MessageBox.alert("提示","操作成功！");
			ds.rejectChanges();
			grid.store.reload(); 
		},failure:function(){
			Ext.MessageBox.alert("提示", "操作失败！"); 
		}
	});  
}

}); 